package br.inf.ufrgs.br.usixml4cdc.rendering.javadesktop;

import javax.swing.JFrame;
import org.w3c.dom.Element;

import br.inf.ufrgs.br.usixml4cdc.rendering.UsiXMLElementRenderer;
import br.inf.ufrgs.br.usixml4cdc.rendering.UsiXMLInterfaceRenderer;
import br.inf.ufrgs.br.usixml4cdc.rendering.javadesktop.components.UsiXMLJavaDesktopWindowRenderer;
import br.inf.ufrgs.usixml4cdc.exceptions.ParsingErrorException;
import br.inf.ufrgs.usixml4cdc.exceptions.RenderingErrorException;

public class UsiXMLJavaDesktopInterfaceRenderer extends
		UsiXMLInterfaceRenderer {

	private UsiXMLElementRenderer mainWindowRenderer = null;
			
	private JFrame mainWindow = null;
	
	public UsiXMLJavaDesktopInterfaceRenderer() {
		this.mainWindowRenderer = 
			new UsiXMLJavaDesktopWindowRenderer(this);
	}
	
	public void renderInterface(Element cuiModel) 
		throws RenderingErrorException, ParsingErrorException {
		
	
            Element window = (Element)cuiModel.getElementsByTagName("window").item(0);
         
            try{
                this.mainWindow = (JFrame)this.mainWindowRenderer.renderElement(window);	 
            }catch (ClassCastException e){
                e.printStackTrace();
                throw new RenderingErrorException();
            }
            
            this.mainWindow.pack();
            this.mainWindow.setVisible(true);
            this.mainWindow.toFront();
	}

}
